import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router';
import CampusBinhai from './components/CampusBinhai.vue';
import CampusChashan from './components/CampusChashan.vue';
import CampusYueqing from './components/CampusYueqing.vue';
import Login from './components/LoginPage.vue';
import StudentSystem from './components/StudentSystem.vue';



Vue.config.productionTip = false
Vue.use(VueRouter);

const router = new VueRouter({
  mode: 'history', // 使用HTML5 History模式
  routes: [
    { path: '/', component: CampusBinhai },
    { path: '/chashan', component: CampusChashan },
    { path: '/leqing', component: CampusYueqing },
    { path: '/login', component: Login },
    { path: '/manager', component: StudentSystem },
  ]
});
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
router.beforeEach((to, from, next) => {
  // 这里可以进行路由拦截的逻辑
  // 例如，检查用户是否认证
  console.log(from)
  console.log(to)
  if(to.fullPath=='/manager'){
    if(from.fullPath!='/login'){
      next({path:'/login'})
    }else{
      next()
    }
  }
  else{
    next()
  }
  // if (false) {
  //   // 如果需要拦截，可以执行next(false)取消导航
  //   // 或者重定向到登录页面
  //   next({ path: '/login' });
  // } else {
    // 如果不需要拦截，就正常导航
  // }
});
new Vue({
  render: h => h(App),
  router
}).$mount('#app')
